css: Feed sections to CSS lookup code
authorBenjamin Otte <otte@redhat.com>
Sun, 1 Jan 2012 22:16:35 +0000 (23:16 +0100)
committerBenjamin Otte <otte@redhat.com>
Mon, 9 Jan 2012 17:37:53 +0000 (18:37 +0100)
gtk/gtkcsslookup.c
gtk/gtkcsslookupprivate.h
gtk/gtkcssprovider.c
gtk/gtkcssshorthandpropertyimpl.c
gtk/gtkstyleproperties.c

index 3e2130418721d33ff710440ff62e31294a58bafc..c3e6a7316f3c9da055d500107d0c03b07bba5a95 100644 (file)
 #include "gtkcssstylepropertyprivate.h"
 #include "gtkstylepropertiesprivate.h"
 
+typedef struct {
+  GtkCssSection     *section;
+  const GValue      *value;
+} GtkCssLookupValue;
+
 struct _GtkCssLookup {
-  GtkBitmask    *missing;
-  const GValue  *values[1];
+  GtkBitmask        *missing;
+  GtkCssLookupValue  values[1];
 };
 
 GtkCssLookup *
@@ -37,7 +42,7 @@ _gtk_css_lookup_new (void)
   GtkCssLookup *lookup;
   guint n = _gtk_css_style_property_get_n_properties ();
 
-  lookup = g_malloc0 (sizeof (GtkCssLookup) + sizeof (const GValue *) * n);
+  lookup = g_malloc0 (sizeof (GtkCssLookup) + sizeof (GtkCssLookupValue) * n);
   lookup->missing = _gtk_bitmask_new ();
   _gtk_bitmask_invert_range (lookup->missing, 0, n);
 
@@ -67,30 +72,35 @@ _gtk_css_lookup_is_missing (const GtkCssLookup *lookup,
 {
   g_return_val_if_fail (lookup != NULL, FALSE);
 
-  return lookup->values[id] == NULL;
+  return lookup->values[id].value == NULL;
 }
 
 /**
  * _gtk_css_lookup_set:
  * @lookup: the lookup
  * @id: id of the property to set, see _gtk_style_property_get_id()
+ * @section: (allow-none): The @section the value was defined in or %NULL
  * @value: the "cascading value" to use
  *
  * Sets the @value for a given @id. No value may have been set for @id
  * before. See _gtk_css_lookup_is_missing(). This function is used to
- * set the "winning declaration" of a lookup.
+ * set the "winning declaration" of a lookup. Note that for performance
+ * reasons @value and @section are not copied. It is your responsibility
+ * to ensure they are kept alive until _gtk_css_lookup_free() is called.
  **/
 void
-_gtk_css_lookup_set (GtkCssLookup *lookup,
-                     guint         id,
-                     const GValue *value)
+_gtk_css_lookup_set (GtkCssLookup  *lookup,
+                     guint          id,
+                     GtkCssSection *section,
+                     const GValue  *value)
 {
   g_return_if_fail (lookup != NULL);
   g_return_if_fail (_gtk_bitmask_get (lookup->missing, id));
   g_return_if_fail (value != NULL);
 
   _gtk_bitmask_set (lookup->missing, id, FALSE);
-  lookup->values[id] = value;
+  lookup->values[id].value = value;
+  lookup->values[id].section = section;
 }
 
 /**
@@ -130,20 +140,20 @@ _gtk_css_lookup_resolve (GtkCssLookup    *lookup,
        * by following this pseudo-algorithm:
        * 1) Identify all declarations that apply to the element
        */
-      if (lookup->values[i] != NULL)
+      if (lookup->values[i].value != NULL)
         {
           /* 2) If the cascading process (described below) yields a winning
            * declaration and the value of the winning declaration is not
            * ‘initial’ or ‘inherit’, the value of the winning declaration
            * becomes the specified value.
            */
-          if (!G_VALUE_HOLDS (lookup->values[i], GTK_TYPE_CSS_SPECIAL_VALUE))
+          if (!G_VALUE_HOLDS (lookup->values[i].value, GTK_TYPE_CSS_SPECIAL_VALUE))
             {
-              result = lookup->values[i];
+              result = lookup->values[i].value;
             }
           else
             {
-              switch (g_value_get_enum (lookup->values[i]))
+              switch (g_value_get_enum (lookup->values[i].value))
                 {
                 case GTK_CSS_INHERIT:
                   /* 3) if the value of the winning declaration is ‘inherit’,
@@ -159,7 +169,7 @@ _gtk_css_lookup_resolve (GtkCssLookup    *lookup,
                   break;
                 default:
                   /* This is part of (2) above */
-                  result = lookup->values[i];
+                  result = lookup->values[i].value;
                   break;
                 }
             }
index 19001d8cee1c5803aea789c9346a8306cbca58f8..79e557868645963a9bf466d109da008550520c77 100644 (file)
@@ -22,6 +22,7 @@
 
 #include <glib-object.h>
 #include "gtk/gtkbitmaskprivate.h"
+#include "gtk/gtkcsssection.h"
 #include "gtk/gtkstylecontext.h"
 #include "gtk/gtkstyleproperties.h"
 
@@ -38,6 +39,7 @@ gboolean                _gtk_css_lookup_is_missing              (const GtkCssLoo
                                                                  guint               id);
 void                    _gtk_css_lookup_set                     (GtkCssLookup       *lookup,
                                                                  guint               id,
+                                                                 GtkCssSection      *section,
                                                                  const GValue       *value);
 GtkStyleProperties *    _gtk_css_lookup_resolve                 (GtkCssLookup       *lookup,
                                                                  GtkStyleContext    *context);
index f24ef0d098f2848cda05403f1f330535e5a699de..102708697f82afeb59bd66c5c3e98dd27a56bb7f 100644 (file)
@@ -1560,7 +1560,7 @@ gtk_css_style_provider_lookup (GtkStyleProviderPrivate *provider,
           if (!_gtk_css_lookup_is_missing (lookup, id))
             continue;
 
-          _gtk_css_lookup_set (lookup, id, &value->value);
+          _gtk_css_lookup_set (lookup, id, value->section, &value->value);
         }
     }
 }
index 38d303323d7763061d92297bc6ff6d379c5d8459..023a38fb4bcbb18016d449ebd104fc6ae872e371 100644 (file)
@@ -618,7 +618,8 @@ pack_border_color (GValue             *value,
 }
 
 static void
-_gtk_css_shorthand_property_register (GParamSpec               *pspec,
+_gtk_css_shorthand_property_register (const char               *name,
+                                      GType                     value_type,
                                       const char              **subproperties,
                                       GtkStyleUnpackFunc        unpack_func,
                                       GtkStylePackFunc          pack_func,
@@ -630,12 +631,11 @@ _gtk_css_shorthand_property_register (GParamSpec               *pspec,
   g_return_if_fail (unpack_func != NULL);
 
   node = g_object_new (GTK_TYPE_CSS_SHORTHAND_PROPERTY,
-                       "name", pspec->name,
-                       "value-type", pspec->value_type,
+                       "name", name,
+                       "value-type", value_type,
                        "subproperties", subproperties,
                        NULL);
 
-  node->pspec = pspec;
   node->pack_func = pack_func;
   node->unpack_func = unpack_func;
   node->parse_func = parse_func;
@@ -653,58 +653,44 @@ _gtk_css_shorthand_property_init_properties (void)
   const char *border_color_subproperties[] = { "border-top-color", "border-right-color", "border-bottom-color", "border-left-color", NULL };
   const char *border_image_subproperties[] = { "border-image-source", "border-image-slice", "border-image-width", "border-image-repeat", NULL };
 
-  _gtk_css_shorthand_property_register   (g_param_spec_boxed ("font",
-                                                              "Font Description",
-                                                              "Font Description",
-                                                              PANGO_TYPE_FONT_DESCRIPTION, 0),
+  _gtk_css_shorthand_property_register   ("font",
+                                          PANGO_TYPE_FONT_DESCRIPTION,
                                           font_subproperties,
                                           unpack_font_description,
                                           pack_font_description,
                                           NULL);
-  _gtk_css_shorthand_property_register   (g_param_spec_boxed ("margin",
-                                                              "Margin",
-                                                              "Margin",
-                                                              GTK_TYPE_BORDER, 0),
+  _gtk_css_shorthand_property_register   ("margin",
+                                          GTK_TYPE_BORDER,
                                           margin_subproperties,
                                           unpack_margin,
                                           pack_margin,
                                           NULL);
-  _gtk_css_shorthand_property_register   (g_param_spec_boxed ("padding",
-                                                              "Padding",
-                                                              "Padding",
-                                                              GTK_TYPE_BORDER, 0),
+  _gtk_css_shorthand_property_register   ("padding",
+                                          GTK_TYPE_BORDER,
                                           padding_subproperties,
                                           unpack_padding,
                                           pack_padding,
                                           NULL);
-  _gtk_css_shorthand_property_register   (g_param_spec_boxed ("border-width",
-                                                              "Border width",
-                                                              "Border width, in pixels",
-                                                              GTK_TYPE_BORDER, 0),
+  _gtk_css_shorthand_property_register   ("border-width",
+                                          GTK_TYPE_BORDER,
                                           border_width_subproperties,
                                           unpack_border_width,
                                           pack_border_width,
                                           NULL);
-  _gtk_css_shorthand_property_register   (g_param_spec_int ("border-radius",
-                                                            "Border radius",
-                                                            "Border radius, in pixels",
-                                                            0, G_MAXINT, 0, 0),
+  _gtk_css_shorthand_property_register   ("border-radius",
+                                          G_TYPE_INT,
                                           border_radius_subproperties,
                                           unpack_border_radius,
                                           pack_border_radius,
                                           border_radius_value_parse);
-  _gtk_css_shorthand_property_register   (g_param_spec_boxed ("border-color",
-                                                              "Border color",
-                                                              "Border color",
-                                                              GDK_TYPE_RGBA, 0),
+  _gtk_css_shorthand_property_register   ("border-color",
+                                          GDK_TYPE_RGBA,
                                           border_color_subproperties,
                                           unpack_border_color,
                                           pack_border_color,
                                           border_color_shorthand_value_parse);
-  _gtk_css_shorthand_property_register   (g_param_spec_boxed ("border-image",
-                                                              "Border Image",
-                                                              "Border Image",
-                                                              GTK_TYPE_BORDER_IMAGE, 0),
+  _gtk_css_shorthand_property_register   ("border-image",
+                                          GTK_TYPE_BORDER_IMAGE,
                                           border_image_subproperties,
                                           _gtk_border_image_unpack,
                                           _gtk_border_image_pack,
index bef1fbfc487d1d0e366536d8abb9ecb8d82dff4a..0431905b1ddd50896cf01bd39de5f85e97c130cf 100644 (file)
@@ -341,7 +341,7 @@ gtk_style_properties_provider_lookup (GtkStyleProviderPrivate *provider,
       if (value == NULL)
         continue;
 
-      _gtk_css_lookup_set (lookup, id, value);
+      _gtk_css_lookup_set (lookup, id, NULL, value);
     }
 }